function TabSelect(tab, con, addClass, obj) {
	var jQuery_self = obj;
	var jQuery_nav = jQuery(tab);
	jQuery_nav.removeClass(addClass), jQuery_self.addClass(addClass);
	var jQuery_index = jQuery_nav.index(jQuery_self);
	var jQuery_con = jQuery(con);
	jQuery_con.hide(), jQuery_con.eq(jQuery_index).show();
}

$(function(){
	$('.prd_nav ul li').click(function() { 
		TabSelect(".prd_nav ul li", "div.myintro", "current", jQuery(this)) 
	});
	$('.prd_nav ul li').eq(0).trigger("click");
	
	$('.wall').jaliswall({ item: '.article' });
	$('.sharebtn,#share_box').click(function(){
		$('#share_box').toggle();
	});
	$('.good_sxlist ul li label').click(function(){
		if($(this).hasClass('checked')){
			$(this).addClass('checked');$(this).parent().find('input').attr('checked','checked');
		}
		else{
			$(this).parent().find('input').attr('checked','checked');$(this).parent().siblings().find('input').attr('checked','');
			$(this).addClass('checked');$(this).parent().siblings().find('label').removeClass('checked');
		}
	});
	
	// 请登录
	$("#btn_please_login").click(function(){
		window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Findex";
	});
	
	// 关闭规格项窗口
	$('#goods_editbox a.icon_close').click(function(){
		$('#goods_editbox').toggle();
	});
	
	// 立即购买还是要先弹出规格项窗口
	$('.buybtn').click(function(){
		$('#goods_editbox').toggle();
	});
	
	
	//评论回复框显示与隐藏
	$(document).bind("click", function(e){
		if ($(e.target).closest("#add_comment").length == 0 && $(e.target).closest("#reply_comment").length == 0) {
			$("#add_comment").hide();
			$("#reply_comment").hide();
		}
		if ($(e.target).closest("#doCommentLi").length != 0) {
			//登录显示评论框,未登录引导登录
			$.ajax({
				type : 'POST',
				url : rootPath + "/home/isLogin",
				async : true,
				dataType : 'json',
				success : function(json) {
					if (json.code == '1') {
//						$("#add_comment").show();
						//使用商品评价功能
						var url = wxRootUrl +"/wx/evaluation/toOrderEvaluation";
						var productId = $("#productId").val();
						var shareId = $("#shareInfoId").val();
						var backUrl = "/wx/share/detail?id="+shareId;
						console.log(backUrl);
						var form = $('<form></form>');  
						form.attr('action', url);  
						form.attr('method', 'post');
						form.attr('target', '_self');
						form.append("<input type='hidden' name='productId'  value='"+productId+"'/>");
						form.append("<input type='hidden' name='backUrl'  value='"+backUrl+"'/>");
						form.appendTo("body");
						form.submit();
					} else {
						//未登录进行授权登录
						var shareId = $("#shareInfoId").val();
						var index = layer.confirm("登录后才评论，请先登录！",{btn:['去登录','下次再说']},function(){
							//授权登录
							window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Fshare%2Fdetail%3Fid%3D"+shareId;
						},function(){
							layer.close(index);
						});
					}
				}
			});
		}
		if ($(e.target).closest("dt[name='doCommentDt']").length != 0) {
			//登录显示评论框,未登录引导登录
			$.ajax({
				type : 'POST',
				url : rootPath + "/home/isLogin",
				async : true,
				dataType : 'json',
				success : function(json) {
					if (json.code == '1') {
//						$("#reply_comment").show();
						//使用商品评价功能
						var url = rootPath +"/wx/evaluation/toOrderEvaluation";
						var productId = $("#productId").val();
						var shareId = $("#shareInfoId").val();
						var form = $('<form></form>');  
						form.attr('action', url);  
						form.attr('method', 'post');
						form.attr('target', '_self');
						form.append("<input type='hidden' name='productId'  value='"+productId+"'/>");
						form.append("<input type='hidden' name='backUrl'  value='/wx/share/detail?id='"+shareId+"/>");
						form.appendTo("body");
						form.submit();
					} else {
						//未登录进行授权登录
						var shareId = $("#shareInfoId").val();
						var index = layer.confirm("登录后才评论，请先登录！",{btn:['去登录','下次再说']},function(){
							//授权登录
							window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Fshare%2Fdetail%3Fid%3D"+shareId;
						},function(){
							layer.close(index);
						});
					}
				}
			});
		}
	});

	//轮播
	var swiper = new Swiper('.swiper-container', {
		autoplay: 3000,
		speed: 500,
		nextButton: '.swiper-button-next',
		prevButton: '.swiper-button-prev',
		pagination: '.swiper-pagination',
		paginationType: 'fraction'
	});

	// 确认添加到的购物车
	$("#btn_buy_confirm").click(function(){
		// 规格项选择
		var flag = true;
		var spec = [];
		$("div[name='spec_list']").each(function(){
			var spec_name= $(this).find("h3").text();
			var select_li = $(this).next("div.bd").find("label.checked");
			var selected_num = select_li.length;
			if(selected_num == 0){
				layer.msg('请选择'+spec_name,{time:2000});
				flag = false;
			}else{
				select_li.each(function(){
					spec.push({id:$(this).attr("spec_id"),specName:spec_name,specValue:$(this).text()});
				});
			}
		});

		if(!flag){
			return false;
		}

		// 添加购物车
		var url = rootPath + "/wx/shoppingcart/add";
		var params = {
				productId : $("#v_product_id").val(),
				buyNum : 1,
				addFlag : 1,
				specListJson:JSON.stringify(spec)
		};
		$.ajax({
			type : "post",
			url : url,
			data : params,
			datatype : "json",
			success : function(json) {
				if (json.resultCode == '1') {
					layer.msg('加入购物车成功',{time:1000});
					$('#goods_editbox').toggle();
				}
			},
			error : function() {
				layer.msg('暂时无法加入购物车',{time:1000});
			}
		});
	});

	// 商品规格项的选中
	$('.good_sxlist ul li label').click(function(){
		if($(this).hasClass('checked')){
			$(this).addClass('checked');
		}else{
			$(this).addClass('checked');
			$(this).parent().siblings().find('label').removeClass('checked');
		}
		var spec_price = 0;
		$('.good_sxlist ul li label.checked').each(function(){
			spec_price = spec_price + parseFloat($(this).parent().attr("spec_price"));
		});
		var last_price = spec_price + parseFloat($("#main_produt_price").val());
		// $("#spec_selector_product_price").text(numberRand2(last_price));
		var tmp_price = numberRand2(last_price);
		$("#spec_selector_product_price").html("￥<em>"+numberInteger(tmp_price)+"</em>"+numberDecimal(tmp_price));
	});

	// 添加到购物车
	$("#btn_add_shoppingcart").click(function() {
		var buy_num = $("#buy_num").val();
		if(!buy_num || buy_num == 0){
			layer.msg('请选择购买数量',{time:1000});
			return false;
		}

		// 规格项选择
		var flag = true;
		var spec = [];
		$("div[name='spec_list']").each(function(){
			var spec_name= $(this).find("h3").text();
			var select_li = $(this).next("div.bd").find("label.checked");
			var selected_num = select_li.length;
			if(selected_num == 0){
				layer.msg('请选择'+spec_name,{time:2000});
				flag = false;
			}else{
				select_li.each(function(){
					spec.push({id:$(this).attr("spec_id"),specName:spec_name,specValue:$(this).text()});
				});
			}
		});
		if(!flag){
			return false;
		}
		
		$.ajax({
			type : 'POST',
			url : rootPath + "/home/isLogin",
			async : true,
			dataType : 'json',
			success : function(json) {
				if (json.code == '1') {
					//立即购买
					var url = rootPath + "/wx/shoppingcart/directAdd";
					var form = $('<form></form>');
				    form.attr('action', url);
				    form.attr('method', 'post');
				    form.attr('target', '_self');
				    form.appendTo("body");
				    form.append($("<input type='hidden' name='addFlag' value='1'/>"));
				    form.append($("<input type='hidden' name='directBuy' value='1'/>"));
				    form.append($("<input type='hidden' name='productId' value='"+$("#product_id").val()+"'/>"));
				    form.append($("<input type='hidden' name='specListJson' value='"+JSON.stringify(spec)+"'/>"));
				    form.append($("<input type='hidden' name='buyNum' value='"+buy_num+"'/>"));
				    form.append($("<input type='hidden' name='shareId' value='"+$("#shareInfoId").val()+"'/>"));
				    form.submit();
				} else {
					//未登录进行授权登录
					var shareId = $("#shareInfoId").val();
					var index = layer.confirm("登录后才能购买，请先登录！",{btn:['去登录','下次再说']},function(){
						//授权登录
						window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Fshare%2Fdetail%3Fid%3D"+shareId;
					},function(){
						layer.close(index);
					});
				}
			}
		});
	});

	//隐藏用户名
	$(".username").each(function(){
		var userName = hideUserName($(this).text());
		$(this).html(userName);
	});

	var uuid = $("#uuid").val();
	var shareInfoId = $("#shareInfoId").val();
	$.ajax({
		type : 'POST',
		url : rootPath + "/home/isLogin",
		async : true,
		dataType : 'json',
		success : function(json) {
			if (json.code == '1') {
				//登录用户分享自己的链接
				var linkUrl = wxRootUrl + "/wx/share/detail?uuid="+uuid;
				$("#shareLinkUrl").val(linkUrl);
			} else {
				//未登录用户分享本页面链接
				var linkUrl = wxRootUrl + "/wx/share/detail?id="+shareInfoId;
				$("#shareLinkUrl").val(linkUrl);
			}
		}
	});
	
	//微信接口调用参数
	wx.config({
		debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
		appId : $('#appId').val(), // 必填，公众号的唯一标识
		timestamp : $('#timestamp').val(), // 必填，生成签名的时间戳
		nonceStr : $('#nonceStr').val(), // 必填，生成签名的随机串
		signature : $('#signature').val(),// 必填，签名
		jsApiList : [ 'onMenuShareTimeline', 'onMenuShareAppMessage' ] // 必填，需要使用的JS接口列表，所有JS接口列表
	});
	wx.ready(function(){
		wx.checkJsApi({
			jsApiList: [
			            'onMenuShareTimeline',
			            'onMenuShareAppMessage'
			            ]
		});

		//分享朋友
		var shareImage = $("#shareImage").val();
		var shareTitle = $("#shareTitle").val();
		var shareDesc = $("#product_title").val();
		var productId = $("#productId").val();
		
		var linkUrl = $("#shareLinkUrl").val();
		wx.onMenuShareAppMessage({
			title: shareTitle, // 分享标题
			desc: shareDesc, // 分享描述
			link: linkUrl, // 分享链接，该链接域名必须与当前企业的可信域名一致
			imgUrl: shareImage, // 分享图标
			success: function () {
				// 用户确认分享后执行的回调函数
				shareNotify(shareInfoId,uuid,productId);
			},
			cancel: function () {
				// 用户取消分享后执行的回调函数
				$('#share_box').hide();
			},
			fail: function (res) {
				alert('wx.onMenuShareAppMessage:fail: '+JSON.stringify(res));
			}
		});

		//分享朋友圈
		wx.onMenuShareTimeline({
			title: shareTitle, // 分享标题
			link: linkUrl, // 分享链接，该链接域名必须与当前企业的可信域名一致
			imgUrl: shareImage, // 分享图标
			success: function () {
				// 用户确认分享后执行的回调函数
				shareNotify(shareInfoId,uuid,productId);
			},
			cancel: function () {
				// 用户取消分享后执行的回调函数
				$('#share_box').hide();
			},
			fail: function (res) {
				alert('wx.onMenuShareTimeline:fail: '+JSON.stringify(res));
			}
		});
	});
	wx.error(function(res){
//		alert(JSON.stringify(res));
	});
})

//编辑购物车数量
function editShopcartNum(_this) {
	var $this = $(_this);
	var buy_num = $("#buy_num").val() || '1';
	if (isNaN(buy_num) || !(/^\d+$/.test(buy_num))) {
		layer.msg('只能输入整数', {
			time : 1000
		});
		return false;
	}
	var int_buy_num = parseInt(buy_num);
	if (int_buy_num < 1) {
		$("#buy_num").val("1");
		return;
	}
	if ($this.attr("id") == 'subtract_num') { // + 
		if (int_buy_num > 1) {
			$("#buy_num").val(int_buy_num - 1);
		}
		if (int_buy_num == 1) {
			$this.removeClass().addClass("icon_jian_gray");
		}
	} else { // -
		$("#buy_num").val(int_buy_num + 1);
		if ($("#subtract_num").attr('class') == "icon_jian_gray") {
			$("#subtract_num").removeClass().addClass("icon_jian");
		}
	}
}

/**
 * 用户点赞
 */
function doShareInfoLike(this_){
	var shareId = $("#shareInfoId").val();
	var url = rootPath + "/wx/share/doShareInfoLike";
	//已登录用户才能点赞
	$.ajax({
		type : "post",
		url : url,
		data : {shareId: shareId},
		datatype : "json",
		success : function(jsonObject) {
			if (jsonObject.resultCode == '1') {
				$(this_).closest("li").addClass("current");
				$(this_).closest("a").removeAttr("onclick");
				var likeNum = $("#likeNum").text();
				$("#likeNum").text(parseInt(likeNum) + 1);
			} else if (jsonObject.resultCode == '-1'){
				$(this_).closest("li").addClass("current");
				$(this_).closest("a").removeAttr("onclick");
			} else {
				layer.msg('点赞失败',{time:1000});
			}
		},
		error : function() {
			layer.msg('点赞失败',{time:1000});
		}
	});
	
	/**
	 * 收藏暂时不用登录
	$.ajax({
		type : 'POST',
		url : rootPath + "/home/isLogin",
		async : true,
		dataType : 'json',
		success : function(json) {
			if (json.code == '1') {
				//已登录用户才能点赞
				$.ajax({
					type : "post",
					url : url,
					data : {shareId: shareId},
					datatype : "json",
					success : function(jsonObject) {
						if (jsonObject.resultCode == '1') {
							$(this_).closest("li").addClass("current");
							$(this_).closest("a").removeAttr("onclick");
							var likeNum = $("#likeNum").text();
							$("#likeNum").text(parseInt(likeNum) + 1);
						} else if (jsonObject.resultCode == '-1'){
							$(this_).closest("li").addClass("current");
							$(this_).closest("a").removeAttr("onclick");
						} else {
							layer.msg('点赞失败',{time:1000});
						}
					},
					error : function() {
						layer.msg('点赞失败',{time:1000});
					}
				});
			} else {
				//未登录进行授权登录
				var shareId = $("#shareInfoId").val();
				var index = layer.confirm("登录后才能点赞，请先登录！",{btn:['去登录','下次再说']},function(){
					//授权登录
					window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Fshare%2Fdetail%3Fid%3D"+shareId;
				},function(){
					layer.close(index);
				});
			}
		}
	});
	*/
}

/**
 * 用户收藏
 */
function doShareInfoFavorite(this_){
	var url = rootPath + "/wx/share/doShareInfoFavorite";
	$.ajax({
		type : 'POST',
		url : rootPath + "/home/isLogin",
		async : true,
		dataType : 'json',
		success : function(json) {
			if (json.code == '1') {
				var shareId = $("#shareInfoId").val();
				//已登录用户才能收藏
				$.ajax({
					type : "post",
					url : url,
					data : {shareId: shareId},
					datatype : "json",
					success : function(jsonObject) {
						if (jsonObject.resultCode == '1') {
							$(this_).closest("li").addClass("current");
							$(this_).closest("a").attr("onclick", "removeShareInfoFavorite(this);");
							var favoriteNum = $("#favoriteNum").text();
							$("#favoriteNum").text(parseInt(favoriteNum) + 1);
						}else {
							layer.msg('收藏失败',{time:1000});
						}
					},
					error : function() {
						layer.msg('收藏失败',{time:1000});
					}
				});
			} else {
				//未登录进行授权登录
				var shareId = $("#shareInfoId").val();
				var index = layer.confirm("登录后才能收藏，请先登录！",{btn:['去登录','下次再说']},function(){
					//授权登录
					window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Fshare%2Fdetail%3Fid%3D"+shareId;
				},function(){
					layer.close(index);
				});
			}
		}
	});
}

/**
 * 用户取消收藏
 */
function removeShareInfoFavorite(this_){
	var url = rootPath + "/wx/share/removeShareInfoFavorite";
	$.ajax({
		type : 'POST',
		url : rootPath + "/home/isLogin",
		async : true,
		dataType : 'json',
		success : function(json) {
			if (json.code == '1') {
				//已登录用户才能取消收藏
				var shareId = $("#shareInfoId").val();
				$.ajax({
					type : "post",
					url : url,
					data : {shareId: shareId},
					datatype : "json",
					success : function(jsonObject) {
						if (jsonObject.resultCode == '1') {
							$(this_).closest("li").removeClass("current");
							$(this_).closest("a").attr("onclick", "doShareInfoFavorite(this);");
							var favoriteNum = $("#favoriteNum").text();
							$("#favoriteNum").text(parseInt(favoriteNum) - 1);
						}else {
							layer.msg('取消收藏失败',{time:1000});
						}
					},
					error : function() {
						layer.msg('取消收藏失败',{time:1000});
					}
				});
			} else {
				//未登录进行授权登录
				var shareId = $("#shareInfoId").val();
				var index = layer.confirm("登录后才能取消收藏，请先登录！",{btn:['去登录','下次再说']},function(){
					//授权登录
					window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Fshare%2Fdetail%3Fid%3D"+shareId;
				},function(){
					layer.close(index);
				});
			}
		}
	});
}

//分享成功后回调
function shareNotify(shareId, uuid, productId){
	$.ajax({
		type : 'POST',
		url : rootPath + "/home/isLogin",
		async : true,
		dataType : 'json',
		success : function(json) {
			if (json.code == '1') {
				//登录用户才回调创建新分享记录
				$.ajax({
					type:"post",
					url:rootPath+"/wx/share/doShareInfoShared",
					data:{shareId: shareId, uuid: uuid, productId: productId},
					datatype: "json",
					success:function(json){
						if (json.resultCode == "1") {
							console.log(json.resultMsg);
						} else {
							console.log(json.resultMsg);
						}
						//回显
						var shareNum = $("#shareNum").text();
						$("#shareNum").text(parseInt(shareNum) + 1);
					},
					error: function(json){
						console.log(json.resultMsg);
					}
				});
			}
		}
	});
}

//评论用户评论
function doCommentUserComment(parentCommentId, nickName){
	//登录用户才能评论
	$.ajax({
		type : 'POST',
		url : rootPath + "/home/isLogin",
		async : true,
		dataType : 'json',
		success : function(json) {
			if (json.code == '1') {
				setTimeout(function(){
					$("#replyCommentContent").focus();
				},50);
				$("#replyCommentContent").attr("placeholder","回复："+nickName);
				$("#parentCommentId").val(parentCommentId);
				$("#parentCommentName").val(nickName);
				$("#reply_comment").show();
			} else {
				//未登录进行授权登录
				var shareId = $("#shareInfoId").val();
				var index = layer.confirm("登录后才能评论，请先登录！",{btn:['去登录','下次再说']},function(){
					//授权登录
					window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Fshare%2Fdetail%3Fid%3D"+shareId;
				},function(){
					layer.close(index);
				});
			}
		}
	});
}

//评论分享信息
function publishShareComment(this_){
	//登录用户才能评论
	$.ajax({
		type : 'POST',
		url : rootPath + "/home/isLogin",
		async : true,
		dataType : 'json',
		success : function(json) {
			if (json.code == '1') {
				//检测登录成功,发布评论
				var shareId = $("#shareInfoId").val();
				var parentCommentId = 0;
				var shareCommentContent = $("#shareCommentContent").val();
				if (!shareCommentContent) {
					layer.msg('必须填写评论内容',{time:1000});
					return;
				}
				if (shareCommentContent.length > 300) {
					layer.msg('评论内容最多300字',{time:1000});
					return;
				}
				$(this_).removeAttr("onclick");
				$("#add_comment").hide();
				$.ajax({
					type:"post",
					url:rootPath+"/wx/share/publishShareComment",
					data:{shareId: shareId, parentCommentId: parentCommentId, commentContent: shareCommentContent},
					datatype: "json",
					success:function(json){
						if (json.resultCode == "1") {
							layer.msg('评论成功',{time:1000});
							setTimeout(function(){
								window.location.reload();
							},1500);
						} else {
							console.log(json.resultMsg);
						}
					},
					error: function(json){
						console.log(json.resultMsg);
					}
				});
			} else {
				//未登录进行授权登录
				var shareId = $("#shareInfoId").val();
				var index = layer.confirm("登录后才能评论，请先登录！",{btn:['去登录','下次再说']},function(){
					//授权登录
					window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Fshare%2Fdetail%3Fid%3D"+shareId;
				},function(){
					layer.close(index);
				});
			}
		}
	});
}

//回复评论
function publishReplyComment(this_){
	//登录用户才能评论
	$.ajax({
		type : 'POST',
		url : rootPath + "/home/isLogin",
		async : true,
		dataType : 'json',
		success : function(json) {
			if (json.code == '1') {
				//检测登录成功,发布评论
				var shareId = $("#shareInfoId").val();
				var parentCommentId = $("#parentCommentId").val();
				var parentCommentName = $("#parentCommentName").val();
				var replyCommentContent = $("#replyCommentContent").val();
				if (!replyCommentContent) {
					layer.msg('必须填写评论内容',{time:1000});
					return;
				}
				if (replyCommentContent.length > 300) {
					layer.msg('评论内容最多300字',{time:1000});
					return;
				}
				$(this_).removeAttr("onclick");
				$("#reply_comment").hide();
				$.ajax({
					type:"post",
					url:rootPath+"/wx/share/publishShareComment",
					data:{shareId: shareId, parentCommentId: parentCommentId, parentCommentName: parentCommentName, commentContent: replyCommentContent},
					datatype: "json",
					success:function(json){
						if (json.resultCode == "1") {
							layer.msg('评论成功',{time:1000});
							setTimeout(function(){
								window.location.reload();
							},1500);
						} else {
							layer.msg(json.resultMsg,{time:1000});
						}
					},
					error: function(json){
						console.log(json.resultMsg);
					}
				});
			} else {
				//未登录进行授权登录
				var shareId = $("#shareInfoId").val();
				var index = layer.confirm("登录后才能评论，请先登录！",{btn:['去登录','下次再说']},function(){
					//授权登录
					window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Fshare%2Fdetail%3Fid%3D"+shareId;
				},function(){
					layer.close(index);
				});
			}
		}
	});
}

//评论点赞
function doShareCommentLike(this_, commentId){
	//登录用户才能点赞
	$.ajax({
		type : 'POST',
		url : rootPath + "/home/isLogin",
		async : true,
		dataType : 'json',
		success : function(json) {
			if (json.code == '1') {
				$.ajax({
					type : "post",
					url : url,
					data : {commentId: commentId},
					datatype : "json",
					success : function(jsonObject) {
						if (jsonObject.resultCode == '1') {
							$(this_).addClass("current");
							$(this_).closest("a").removeAttr("onclick");
							var likeNum = $(this_).find("span[name='commentLikeQuantity']").text();
							$(this_).find("span[name='commentLikeQuantity']").text(parseInt(likeNum) + 1);
						} else {
							layer.msg('点赞失败',{time:1000});
						}
					},
					error : function() {
						layer.msg('点赞失败',{time:1000});
					}
				});
			} else {
				//未登录进行授权登录
				var shareId = $("#shareInfoId").val();
				var index = layer.confirm("登录后才能点赞，请先登录！",{btn:['去登录','下次再说']},function(){
					//授权登录
					window.location.href = rootPath + "/wx/my/toBindAccountPage?goToUrl=%2Fwx%2Fshare%2Fdetail%3Fid%3D"+shareId;
				},function(){
					layer.close(index);
				});
			}
		}
	});
}

/**
 * 查询评论的所有回复
 * @param commentId
 */
function queryAllReply(this_,commentId) {
	var replyDiv = $(this_).closest("div[class='boxs_1_3_con']").find("div[name='replyDiv']");
	$(this_).closest("strong").hide();
	$.ajax({
		type : "post",
		url : rootPath + "/wx/share/listAllReply",
		data : {commentId: commentId},
		datatype : "json",
		success : function(jsonObject) {
			if (jsonObject.resultCode == '1') {
				$.each(jsonObject.replyList, function(index,reply){
					if (index != 0) {						
						replyDiv.append("<p name='reply_p'>"+reply.commentNickname+"："+reply.commentContent+"</p>");
					}
				});
			} else {
				layer.msg('查询失败',{time:1000});
			}
			$(this_).closest("strong").next().next().show();
		},
		error : function() {
			layer.msg('查询失败',{time:1000});
		}
	});
}
//展开所有回复
function showAllReply(this_) {
	var replyDiv = $(this_).closest("div[class='boxs_1_3_con']").find("div[name='replyDiv']");
	replyDiv.find("p[name='reply_p']").each(function(){
		$(this).show();
	});
	$(this_).closest("strong").hide();
	$(this_).closest("strong").next().show();
}
//收起所有回复
function hideAllReply(this_) {
	var replyDiv = $(this_).closest("div[class='boxs_1_3_con']").find("div[name='replyDiv']");
	replyDiv.find("p[name='reply_p']").each(function(){
		$(this).hide();
	});
	$(this_).closest("strong").hide();
	$(this_).closest("strong").prev().show();
}

//微信图片预览
function imageView(this_) {
	var src = $(this_).attr("data-src");
	var srcPre = src + '?x-oss-process=image/resize,m_pad,h_60,w_60';
	/**
	wx.previewImage({
		current : srcPre, // 当前显示图片的http链接  
		urls : [ src ]
		// 需要预览的图片http链接列表  
	})
	*/
	WeixinJSBridge.invoke('imagePreview', {  
		'current': srcPre,  
		'urls': [src]
	});  
}
//隐藏用户名
function hideUserName(userName){
	var hideName = "";
	if (userName.length < 3) {
		hideName = userName.substr(0,1) + "****";
	} else {
		hideName = userName.substr(0,1) + "****";
	}
	return hideName;
}

/**
 * 上拉加载
 */
$(window).on('scroll',function(){
	if($(window).scrollTop()>=$(document).height()-$(window).height()){
		var tag = $("li.current").attr("tag");
		if (tag == "evaluation") {
			var numPerPage = $("#numPerPage").val();
			var currentPage = $("#currentPage").val();
			var pageCount = $("#pageCount").val();
			var productId =  $("#productId").val();
			if(currentPage >= pageCount){
				layer.msg('已经到底了',{time:500});
				return false;
			}
			$.ajax({
				type : "post",
				url : rootPath + "/wx/product/queryProductEvaluation",
				data : {productId: productId,tmpCurrentPage: Number(currentPage)+1, tmpNumPerPage: numPerPage},
				datatype : "json",
				success : function(jsonObject) {
					var numPerPage = $("#numPerPage").val(jsonObject.evaluationPage.numPerPage);
					var currentPage = $("#currentPage").val(jsonObject.evaluationPage.currentPage);
					var pageCount = $("#pageCount").val(jsonObject.evaluationPage.pageCount);
					$.each(jsonObject.evaluationPage.recordList, function(i,record){
						var li = "<li>" +
						"<div class='box4'>" +
						"<div class='pic'>" +
						"<img src='"+imgRootURL+"/"+record.headImage+"?x-oss-process=image/resize,h_100/format,png' onerror='this.src=\""+rootPath+"/statics_wx/images/user_img2.png\"'/>" +
						"</div>" +
						"<div class='item-info'>" +
						"<div class='box4_1'>" +
						"<div class='left'>" +
						"<h2 class='username'>"+hideUserName(record.userName)+"</h2>" +
						"<h3>" +
						"<span class='bg1'>" +
						"<span class='bg2' style='width: "+(record.score*20)+"%'></span>" +
						"</span>" +
						"</h3>" +
						"</div>" +
						"<div class='right'>" +
						"<p>"+record.createTimeStr+"</p>" +
						"</div>" +
						"</div>";
						if (record.filePathList.length > 0){
							li += "<div class='box4_2'>" + 
							"<p>";
						}
						$.each(record.filePathList, function(i, filePath){
							li += "<div style='float:left; margin-left: 5px;'>" +
							"<img class='smallpics' data-src='"+imgRootURL + filePath+"' src='"+imgRootURL + filePath+"?x-oss-process=image/resize,m_pad,h_50,w_50,color_000000/format,png' alt='' onclick='imageView(this);'/>" +
							"</div>";
						});
						if (record.filePathList.length > 0){
							li += "</p></div>";
						}
						li +=	"<div class='box4_2'>" +
						"<p>"+record.content+"</p>" +
						"</div>" +
						"<div class='box4_3'>" +
						"<dl>" +
						"<dt>"+record.productName+"</dt>" +
						"</dl>" +
						"</div>" +
						"</div>" +
						"</div></li>";
						$("#comment_ul").append(li);
					});
				},
				error : function() {
					layer.msg('查询商品失败',{time:1000});
				}
			});
		}
	}
});